package com.lagou.mr.homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class HomeworkReducer extends Reducer<IntWritable, NullWritable, Text, NullWritable> {

    //排名
    private int lineNo = 0;
    //key
    private Text k = new Text();

    //每一条记录调用一次reduce方法，每调用一次排名+1
    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Reducer<IntWritable, NullWritable, Text, NullWritable>.Context context) throws IOException, InterruptedException {

        //排名每一行+1
        lineNo += 1;
        k.set(lineNo + "\t" + key.toString());

        context.write(k, NullWritable.get());
    }
}
